import {ref} from "vue";
import { reactive } from 'vue';
import { isNotVoid, isVoid} from "@/utils/util";

const useTestResultStore = defineStore(
  'testResult',
  {
    state: () => ({
      map: reactive(new Map())
    }),
    actions: {
      addResult(result) {
        if (isVoid(this.map.get(result.reportId))) {
            this.map.set(result.reportId, new Array());
        }
        const list = this.map.get(result.reportId)
        list.push(result)
      },
      getResult(id) {
        if (isVoid(this.map.get(id))) {
            return null
        }
        const list = this.map.get(id)
        if(list.length === 0) {
            return null
        }
        const data = list.shift()
        return data
      },
      cleanResult() {
        this.map = new Map();
      },

    }
  })

export default useTestResultStore
